package clock.hand;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.util.Calendar;

public class MinuteHand extends ClockHand {
    
	public MinuteHand(int axisX, int axisY) {
		super(axisX, axisY);
		this.hand_x = new int[4];
    	hand_x[0] = -3;
    	hand_x[1] = 0;
    	hand_x[2] = 3;
    	hand_x[3] = 0;
        this.hand_y = new int[4];
        hand_y[0] = -5;
        hand_y[1] = 70;
        hand_y[2] = -5;
        hand_y[3] = -10;
        this.hand = new Polygon(hand_x, hand_y, 4);
    }

	@Override
	public void update() {
		this.tick = Calendar.getInstance().get(Calendar.MINUTE);
		this.tick *= 6;
	}

	@Override
	public void draw(Graphics2D g) {
		this.update();
		
		g.translate(this.axisX, this.axisY);
		g.rotate(Math.toRadians(this.tick+180));
		
		if (this.tick >= 0 && this.tick <= 180) g.translate(-2, 0);
		else g.translate(2, 0);
		
		g.setColor(Color.darkGray);
		g.fillPolygon(this.hand);
		
		if (this.tick >= 0 && this.tick <= 180) g.translate(2, 0);
		else g.translate(-2, 0);
		
		g.setColor(Color.BLUE);
		g.fillPolygon(this.hand);
		
		g.rotate(-Math.toRadians(this.tick+180));
		g.translate(-this.axisX, -this.axisY);
	}

}
